#
# Auto dependency checker
#

CFLAGS += -fstack-protector-all
ifndef SRCS
SRCS    := $(wildcard *.c)
endif
OBJS    := $(SRCS:%.c=%.o)

# Add for libsigtracer.so
ifndef _TARGET_DIR_
_TARGET_DIR_ = $(HBLIB_PATH)
endif

.PHONY:	clean

$(_TARGET_DIR_)/$(TARGET_LIB): $(TARGET_LIB)
	@$(MKDIR) -p $(_TARGET_DIR_)
	@$(CP) -uv $(TARGET_LIB) $@

$(TARGET_LIB): $(OBJS) $(EXT_OBJS)
	$(AR) $(AR_FLAGS) $@ $^

clean:
	@$(RM) $(MAKE_LOG_FILE)
	@$(RM) $(DEPEND_FILE_NAME)
	@$(RM) $(TARGET_LIB)
	@$(RM) $(_TARGET_DIR_)/$(TARGET_LIB)
	@$(RM) $(OBJS)

$(DEPEND_FILE_NAME): $(SRCS)
	@$(RM) $@
	$(HB_ECHO) for x in $(SRCS);						\
	do													\
		$(CC) -MM -MT"$${x%.c}.o" $(CFLAGS) $$x >> $@;	\
	done												\

include $(SPLINT_MK)

include $(BUILD_MK)

ifneq "$(MAKECMDGOALS)" "clean"
sinclude $(DEPEND_FILE_NAME)
endif
